<template>
  <!-- 外部链接 -->
  <a v-if="isExternal" :href="to" target="_blank" rel="noopener">
    <slot />
  </a>
  <!-- 内部路由链接 -->
  <router-link v-else :to="to">
    <slot />
  </router-link>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  to: {
    type: String,
    required: true
  }
})

// 判断是否是外部链接
const isExternal = computed(() => {
  return /^(https?:|mailto:|tel:)/.test(props.to)
})
</script> 